package com.example.easyexcel.controller;

import com.example.easyexcel.service.impl.DataMigrationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/api/data-migration")
public class DataMigrationController {

    private final DataMigrationService dataMigrationService;

    public DataMigrationController(DataMigrationService dataMigrationService) {
        this.dataMigrationService = dataMigrationService;
    }

    /**
     * 触发数据迁移
     */
    @PostMapping("/migrate-to-asset-basic")
    public ResponseEntity<String> migrateToAssetBasicInfo() {
        try {
            dataMigrationService.migrateDataToAssetBasicInfo();
            return ResponseEntity.ok("数据迁移成功完成");
        } catch (Exception e) {
            log.error("数据迁移失败: {}", e.getMessage(), e);
            return ResponseEntity.internalServerError().body("数据迁移失败: " + e.getMessage());
        }
    }

    /**
     * 触发接口API数据迁移
     */
    @PostMapping("/migrate-interface-api-to-asset-basic")
    public ResponseEntity<String> migrateInterfaceApiToAssetBasicInfo() {
        try {
            dataMigrationService.migrateInterfaceApiDataToAssetBasicInfo();
            return ResponseEntity.ok("接口API数据迁移成功完成");
        } catch (Exception e) {
            log.error("接口API数据迁移失败: {}", e.getMessage(), e);
            return ResponseEntity.internalServerError().body("接口API数据迁移失败: " + e.getMessage());
        }
    }
}
